/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Compras;

import Controlador.Bean.Compras.Proveedor;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JInternalFrame;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author LiziTa
 */
public class CatalogoSeleccionarProveedor extends javax.swing.JInternalFrame {
TableModel tb= new TableModel();
    /**
     * Creates new form CatalogoSeleccionarProveedor
     */
    public CatalogoSeleccionarProveedor() {
        initComponents();
        SProveedor.setModel(tb);
//        TableRowSorter<TableModel> sorter  = new TableRowSorter<TableModel>((TableModel) SProveedor.getModel());
//         SProveedor.setRowSorter(sorter);
       
     
    }

     private agregarCatalogo aCatalogo;
     
    ArrayList<Proveedor> proveedores= (ArrayList<Proveedor>) Controlador.Service.Compras.GestionCompra.obtenerProveedor();
Proveedor p=new Proveedor();
     
    // List<Proveedor> proveedores = Controlador.Service.Compras.GestionCompra.obtenerProveedor();
    
 
   
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    

   
      class TableModel extends AbstractTableModel{
        
      String[] columnNames = {"IdProveedor","Razon Social", "Direccion", "Ruc" };
           
                        
        @Override
        public int getRowCount()
        {
         
            return proveedores.size();
        }
        
        
        
        @Override
        public int getColumnCount()            
        {
            return columnNames.length;
        }
        
        @Override
        public Object getValueAt(int row, int column)
        {   // {"Razon Social", "Direccion", "Ruc" , "Contacto", "Apellido","Eliminar"};
            Proveedor p= proveedores.get(row);
            switch(column){
                case 0:return p.getIdProveedor();
                case 1: return p.getRazonSocial();
                case 2: return p.getDireccion(); 
                 default: return p.getRuc();
                    
               }
        }
        
        //Used by the JTable object to set the column names
        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
        }
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
                 

       
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */  
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        SProveedor = new javax.swing.JTable();

        setClosable(true);
        setTitle("Seleccionar Proveedor");

        SProveedor.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        SProveedor.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                SProveedorMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(SProveedor);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void SProveedorMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SProveedorMouseClicked
        // TODO add your handling code here:
         if(evt.getClickCount()==2){
            
            int rowSel = SProveedor.getSelectedRow();
            Proveedor pr=proveedores.get(rowSel); 
            agregarCatalogo.txtProveedor.setText(pr.getRazonSocial().toString());
            agregarCatalogo.txtIdProv.setText(pr.getIdProveedor().toString());
            CatalogoSeleccionarProveedor.this.dispose();
           
           
        }
    }//GEN-LAST:event_SProveedorMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JTable SProveedor;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
